<?php

/*
Copyright 2005-2011 Textpattern CMS Project
All Rights Reserved.

This file is part of Textpattern.

Textpattern is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

if (!defined('txp'))
{
	header('HTTP/1.1 403 Forbidden');
	exit('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>403 Forbidden</title></head><body><h1>Forbidden</h1><p>You don\'t have permission to access the requested resource on this server.</p></body></html>');
}

require('txp_base.php');

//------------------------------------------------------------------------------

class TxpAdminController extends SparkController
{
	private $_vars;
	
	//---------------------------------------------------------------------------

	public function __construct($app)
	{		
		parent::__construct($app);

		$this->getCommonVars($this->_vars);
	}
	
	//---------------------------------------------------------------------------

	public function _before_dispatch($method, $params)
	{
		// handle nav menu events
		
		if (!empty($params['get']['event']))
		{
			$this->redirect($params['get']['event']);
		}
		
		return true;
	}

	//---------------------------------------------------------------------------

	protected function newForm($id, $title)
	{
		return
			$this->factory->manufacture('SparkForm', $id, $title)
				->defaultView('default_form')
				->referrer(SparkUtil::self_url())
				->csrfToken(true)
		//		->rejectDuplicateSubmission(true)	// enable once we tie in to Txp's nonce table
				->expires(false)
				->honeypot(true)
				->isHTML5(true)
				->labelExtra_required('')
				->formAttribute('autocomplete', 'off')
					;
	}
	
	//---------------------------------------------------------------------------

	protected function getCommonVars(&$vars)
	{
		if (!isset($this->_vars))
		{
			$this->_vars = array
			(
				'title' => 'Textpattern Content Management System Administration',
				'site_url' => 'http://' . $this->app->get_pref('siteurl'),
				'txp_version' => TXPVersion::CoreVersion,
				'language' => $this->app->language(),
				'charset' => strtolower($this->app->charset()),
				'image_root' => $this->urlToStatic('/img/'),
				'tabs' => array
				(
					'start'        => NULL,
					'content'      => array('categories', 'write', 'articles', 'images', 'files', 'links', 'comments',),
					'presentation' => array('sections', 'pages', 'forms', 'styles',),
					'admin'        => array('diagnostics', 'preferences', 'users', 'visitor_logs', 'plugins', 'import',),
					'extensions'   => NULL,
				),
				'tab_default' => array
				(
					'start'        => '',
					'content'      => 'write',
					'presentation' => 'pages',
					'admin'        => 'users',
					'extensions'   => '',
				),
				'urls' => array
				(
					'categories'   => '/content/categories',
					'write'        => '/content/write',
					'articles'     => '/content/articles',
					'images'       => '/content/images',
					'files'        => '/content/files',
					'links'        => '/content/links',
					'comments'     => '/content/comments',
					'sections'     => '/presentation/sections',
					'pages'        => '/presentation/pages',
					'forms'        => '/presentation/forms',
					'styles'       => '/presentation/styles',
					'diagnostics'  => '/admin/diagnostics',
					'preferences'  => '/admin/preferences',
					'users'        => '/admin/users',
					'visitor_logs' => '/admin/visitor_logs',
					'plugins'      => '/admin/plugins',
					'import'       => '/admin/import',
				),
			);
		}

		$vars = $this->_vars;
	}

	//---------------------------------------------------------------------------
	
}
